package com.chase.flashcleaner

import android.os.Environment
import com.chase.flashcleaner.service.NetworkService
import java.io.File
import java.io.IOException

fun initFiles() {
    val configPath = "${Environment.getExternalStorageDirectory()}/Android/data/com.chase.flashcleaner/config"
    val cleanDirsPath = "$configPath/clean_paths.txt"

    if (!File(configPath).exists()) {
        File(configPath).mkdirs()
    }

    Thread(Runnable {
        var cleanedRawPaths: String? = null

        try {
            cleanedRawPaths = NetworkService.getCleanRawPaths()
        } catch (e: IOException) {
            e.printStackTrace()
        }

        val fileCleanDirs = File(cleanDirsPath)
        fileCleanDirs.apply {
            if (!exists()) {
                createNewFile()
            }
            cleanedRawPaths?.let { writeText(it) }
        }
    }).start()
}